package com.demo.component.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@EnableScheduling
public class MultiThreadTask {

    private static Logger logger = LoggerFactory.getLogger(MultiThreadTask.class);

    @Autowired
    private MultiAsyncThread multiAsyncThread;

    // 任务
    @Scheduled(fixedDelay = 1000000)
    public void task() {
        try {
            for (int i = 0; i < 5; i++)  {
                multiAsyncThread.getAsyncExecutor().execute(new MultiThreadDealService(i));
            }
        } catch (Exception e) {
            logger.error("异步线程异常-", e);
        }
    }

}
